package com.jindy.module.approval.controller;

import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.core.page.TableDataInfo;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.approval.domain.Approval;
import com.jindy.module.approval.service.ApprovalService;
import com.jindy.module.filing.domain.Filing;
import com.jindy.system.service.ISysUserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审批Controller
 *
 * @author zhaoxi
 * @date 2022-12-28
 */

@Api(tags = "业务后台 - 审批管理 ")
@RestController
@RequestMapping("/module/approval")
@Validated
@Slf4j
public class ApprovalController extends BaseController {
    @Autowired
    private ApprovalService approvalService;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询审批数据列表
     */
//    @PreAuthorize("@ss.hasPermi('module:approval:list')")
    @GetMapping("/list")
    public TableDataInfo list(Approval approval){

        startPage();
        List<Approval> list = approvalService.selectApprovalList(approval);
        return getDataTable(list);
    }

    /**
     * 根据id查询审批信息
     */
//    @PreAuthorize("@ss.hasPermi('module:approval:id')")
    @GetMapping(value = "/{id}")
    public AjaxResult get(@PathVariable("id") String id) {
        return AjaxResult.success(approvalService.selectApprovalById(id));
    }

    /**
     * 新增审批数据
     */
    @Log(title = "新增审批", businessType = BusinessType.INSERT)
//    @PreAuthorize("@ss.hasPermi('module:approval:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Approval approval)
    {
        return toAjax(approvalService.insertApproval(approval));
    }

    /**
     * 修改审批数据
     */
    @Log(title = "修改审批", businessType = BusinessType.UPDATE)
//    @PreAuthorize("@ss.hasPermi('module:approval:update')")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody Approval approval) {
        return toAjax(approvalService.updateApproval(approval));
    }

    /**
     * 删除审批
     */
    @Log(title = "删除审批", businessType = BusinessType.DELETE)
//    @PreAuthorize("@ss.hasPermi('module:approval:delete')")
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(approvalService.deleteApprovalById(id));
    }

    /**
     * 批量删除
     */
    @Log(title = "批量删除", businessType = BusinessType.DELETE)
//    @PreAuthorize("@ss.hasPermi('module:approval:deletes')")
    @DeleteMapping("/{ids}")
    public AjaxResult removes(@PathVariable String[] ids)
    {
        return toAjax(approvalService.deleteApprovalByIds(ids));
    }
}
